# coding: utf-8

from __future__ import absolute_import, division, print_function, unicode_literals

import os
import shutil
import zipfile


class GenProjectInit(object):
    @staticmethod
    def generate_demo():
        root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        parent_file_path = os.path.join(root_path, 'demo')
        files = os.listdir(parent_file_path)
        for file in files:
            src_file_path = os.path.join(root_path, 'demo', file)
            target_file_path = os.path.join(os.getcwd(), file)

            # 判断路径对应的文件是否是文件夹或文件
            if os.path.isdir(src_file_path):
                # 判断目标路径下是否存在文件夹
                if os.path.exists(target_file_path):
                    shutil.rmtree(target_file_path)
                    shutil.copytree(src_file_path, target_file_path)
                else:
                    shutil.copytree(src_file_path, target_file_path)

            elif os.path.isfile(src_file_path):
                if os.path.exists(target_file_path):
                    shutil.rmtree(target_file_path)
                    shutil.copyfile(src_file_path, target_file_path)
                else:
                    shutil.copyfile(src_file_path, target_file_path)

    @staticmethod
    def generate_demo_zip():
        root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        parent_file_path = os.path.join(root_path, 'demo.zip')
        wd = os.getcwd()
        with zipfile.ZipFile(parent_file_path, "r") as zf:
            zf.extractall(wd)
        zf.close()
